//=======================================================
// 作者：KingSley
// 描述：通过DOTween实现动画的延迟播放和循环播放
//=======================================================
using UnityEngine;
using System.Collections;
using DG.Tweening;

namespace Babybus.Uno
{
    public class DOTweenLoopAndDelay : MonoBehaviour
    {
        // 两张动画图片分别的位置坐标记录，Image1为循环动画，Image2为延迟动画
        public Vector3 Image1Vector = new Vector3(-150, 0, 0);
        public Vector3 Image2Vector = new Vector3(150, -150, 0);

        private void Start()
        {
            DOTween.useSafeMode = true;
            DOTween.To(() => Image1Vector, x => Image1Vector = x, new Vector3(150, 0, 0), 2).SetLoops(-1, LoopType.Yoyo);
            DOTween.To(() => Image2Vector, x => Image2Vector = x, new Vector3(150, 150, 0), 2).SetDelay(2);
        }

        private void Update()
        {
            GameObject.Find("Image1").transform.localPosition = Image1Vector;
            GameObject.Find("Image2").transform.localPosition = Image2Vector;
        }
    }
}
